from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from copy import copy

class Unit:

    def __init__(self):
        orientation = Vec3()
    
    def Initialize( self, size, attack, defense, range, hex, player, moveCapabilities, model):
        self.model = copy(model)
        self.model.reparentTo(render)
        self.size = size
        self.attack = attack
        self.defense = defense
        self.range = range
        self.hex = hex
        self.Move(hex)
        self.moveCapabilities = moveCapabilities 
        self.player = player
    
    def Merge(self, unit ):
        self.size += unit.size
        unit.size = 0
    
    def Move( self,hex):
        #self.hex = hex
        #test
        self.model.setPos(hex.elevation * 50,hex.elevation, hex.elevation ) 

    def Remove(self):
        self.model.removeNode()

    def Attack( self,unit):
        killed = self.attack * self.size - unit.defense * unit.size
        #dead = unit.attack * unit.size - self.defense * self.size
        if killed > 0:
            unit.size -=killed
        else:
            self.size +=killed

class AlliedInfantry(Unit):
    
    def __init__(self, size, hex, player, model):
        Unit.__init__(self)
        Unit.Initialize(self,size,10, 10, 5, hex, player, 0, model)


class AlliedTank(Unit):
    
    def __init__(self, size, hex, player, model):
        Unit.__init__(self)
        Unit.Initialize(self,size,10, 10, 5, hex, player, 0, model)

class AlliedPlane(Unit):
    
    def __init__(self, size, hex, player, model):
        Unit.__init__(self)
        Unit.Initialize(self,size,10, 10, 5, hex, player, 0, model)

class AxisInfantry(Unit):
    
    def __init__(self, size, hex, player, model):
        Unit.__init__(self)
        Unit.Initialize(self,size,10, 10, 5, hex, player, 0, model)

class AxisTank(Unit):
    
    def __init__(self, size, hex, player, model):
        Unit.__init__(self)
        Unit.Initialize(self,size,10, 10, 5, hex, player, 0, model)


class AxisPlane(Unit):
    
    def __init__(self, size, hex, player, model):
        Unit.__init__(self)
        Unit.Initialize(self,size,10, 10, 5, hex, player, 0, model)


